package org.springblade.common.config;

import com.google.common.collect.Maps;
import com.lark.oapi.Client;
import lombok.Data;
import org.springblade.common.enums.FeishuClientEnum;
import org.springblade.common.utils.feishu.ClientSecure;
import org.springblade.core.log.exception.ServiceException;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.Map;

/**
 * @Description 飞书配置
 * @Author ysq
 * @Date 2024/03/27
 **/
@Data
@Component
@ConfigurationProperties(prefix = "feishu")
public class FeiShuConfiguration {

	/**
	 * 客户端配置
	 */
	private final Map<FeishuClientEnum, ClientSecure> client = Maps.newHashMap();

	/**
	 * 构建client
	 * @param name 枚举类型
	 */
	public Client getClient(FeishuClientEnum name) {
		ClientSecure clientSecure = getClitSecure(name);
		return Client.newBuilder(clientSecure.getAppId(), clientSecure.getAppSecret()).build();
	}

	/**
	 * 获取配置
	 * @param name 枚举类型
	 */
	public ClientSecure getClitSecure(FeishuClientEnum name) {
		if (!client.containsKey(name)) {
			throw new ServiceException("未找到对应飞书配置！");
		}
		return client.get(name);
	}
}
